#include "junix.h"

template<
typename ValueType=int,
typename Compare=std::less<ValueType>
>
struct selection {
	void operator()(ValueType v[], int size)
   	{
		Compare comp;
		for (int i=0;i<size-1;i++) 
		{
			int x=i,j=i+1;
			for (;j<size;j++) 
				if (comp(v[j],v[x])) 
					x = j;
			
			std::swap(v[i],v[x]);
		}
	}
};

int main(int argc, char **argv)
{
	const int sz = 100000;
	std::vector<int> v(sz);
	std::generate(v.begin(),v.end(),
			boost::bind(std::modulus<int>(),boost::bind(rand),sz));
	jtime T;
	T.begin();
	selection<>()(&v[0], v.size());
	T.end();
	T.print();

	/*
	std::copy(v.begin(),v.end(),std::ostream_iterator<int>(std::cout," "));
	std::cout<<std::endl;
	*/
}
